<template>
    <div class='approval'>
      <el-card class="box-card" style="margin-top: 110px; overflow: auto;">
        <div class='title'>
          {{$t('achievements.title1')}}
        </div>
        <div class='menu-search'> 
            <div class='menu-title'>
                <!-- 业务ID -->
                <div class='searchItem'>
                    <span>{{$t('achievements.orderId')}}</span>
                    <el-input v-model='listQuery.orderId' :placeholder="$t('rule.orderId')" size='small'></el-input>
                </div>
                <!-- 客户姓名 -->
                <div class='searchItem'>
                    <span>{{$t('achievements.realName')}}</span>
                    <el-input v-model='listQuery.realName' :placeholder="$t('rule.realName')" size='small'></el-input>
                </div>
                <!-- 手机号 -->
                <div class='searchItem'>
                    <span>{{$t('achievements.phoneNo')}}</span>
                    <el-input v-model='listQuery.phoneNo' :placeholder="$t('rule.phoneNo')" size='small'></el-input>
                </div>
                <!-- 机构名称 -->
                <div class='searchItem'>
                    <span>{{$t('achievements.orgName')}}</span>
                    <el-select v-model='listQuery.orgId' filterable :placeholder="$t('rule.choose')" size='small'>
                        <el-option
                        v-for='item in mechanism'
                        :key='item.id'
                        :label='item.orgName'
                        :value='item.id'>
                        </el-option>
                    </el-select>
                </div>
                <!-- 审批结果 -->
                <div class='searchItem'>
                    <span>{{$t('achievements.result')}}</span>
                    <el-select v-model='listQuery.approvalResult' size='small'>
                          <el-option
                          v-for='item in result'
                          :key='item.value'
                          :label='item.label'
                          :value='item.value'>
                          </el-option>
                      </el-select>
                </div>
                <!-- 订单状态 -->
                <div class='searchItem'>
                    <span>{{$t('orderQuery.orderStatus')}}</span>
                    <el-select v-model='listQuery.checkStatus' size='small'>
                          <el-option
                          v-for='item in orderStatus'
                          :key='item.value'
                          :label='item.label'
                          :value='item.value'>
                          </el-option>
                      </el-select>
                </div>
                <!-- 审批人 -->
                <div class='searchItem'>
                    <span>{{$t('achievements.loanUser')}}</span>
                    <el-input v-model='listQuery.loanUser' :placeholder="$t('rule.loanUser')" size='small'></el-input>
                </div>
                <!-- 续贷订单 -->
                <div class='searchItem'>
                  <span>{{$t('lenders.continuedLoan')}}</span>
                  <el-select v-model='listQuery.continuedLoanStatus' size='small'>
                      <el-option
                      v-for='item in conLoan'
                      :key='item.value'
                      :label='item.label'
                      :value='item.value'>
                      </el-option>
                  </el-select>
                </div>
                <!--申请时间-->
                <div class='searchItem searchItem-date'>
                    <span>{{$t('achievements.crtTime')}}</span>
                    <el-date-picker
                      size='small'
                      v-model="listQuery.beginDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :placeholder="$t('rule.beginDate')"
                    ></el-date-picker>
                    <b>{{$t('approval.go')}}</b>
                    <el-date-picker
                      size='small'
                      v-model="listQuery.endDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :placeholder="$t('rule.endDate')"
                    ></el-date-picker>
                </div>
                <!-- 放款时间 -->
                <div class='searchItem searchItem-date'>
                    <span>{{$t('orderQuery.loanTime')}}</span>
                    <el-date-picker
                      size='small'
                      v-model="listQuery.lendBeginDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :placeholder="$t('rule.beginDate')"
                    ></el-date-picker>
                    <b>{{$t('approval.go')}}</b>
                    <el-date-picker
                      size='small'
                      v-model="listQuery.lendEndDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :placeholder="$t('rule.endDate')"
                    ></el-date-picker>
                </div>
                <!-- 到期时间 -->
                <div class='searchItem searchItem-date'>
                    <span>{{$t('orderQuery.lastPayDate')}}</span>
                    <el-date-picker
                      size='small'
                      v-model="listQuery.repaymengtBeginDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :placeholder="$t('rule.beginDate')"
                    ></el-date-picker>
                    <b>{{$t('approval.go')}}</b>
                    <el-date-picker
                      size='small'
                      v-model="listQuery.repaymengtEndDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :placeholder="$t('rule.endDate')"
                    ></el-date-picker>
                </div>
                <!-- 结清还款时间 -->
                <div class="searchItem searchItem-date">
                    <span style="display: inline-block;width: 100px;">{{$t('dispatch.settleTime')}}</span>
                    <el-date-picker
                      size='small'
                      v-model="listQuery.beginSettleTime"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :placeholder="$t('rule.beginDate')"
                    ></el-date-picker>
                    <b>{{$t('approval.go')}}</b>
                    <el-date-picker
                      size='small'
                      v-model="listQuery.endSettleTime"
                      type="date"
                      value-format="yyyy-MM-dd"
                      :placeholder="$t('rule.endDate')"
                    ></el-date-picker>
                </div>
            </div>
            <div class='menu-title-btn'>
                <button type='button' @click='search'>
                    {{$t('btn.query')}}
                </button>
                <button type='button' @click='reset'>
                    {{$t('btn.reset')}}
                </button>
                <!-- 导出 -->
                <button type='button' @click="handleDownload" :disabled="expDis" v-if="orderQuery_btn_export">
                    {{$t('btn.export')}}
                </button>
                <!-- 解绑银行卡 -->
                <button type='button' @click='untie' :disabled="untieDis" v-if="orderQuery_btn_untie">
                    {{$t('orderQuery.untie')}}
                </button>
                <!-- 重新放款 -->
                <button type='button' @click='again' :disabled="againDis" v-if="orderQuery_btn_again">
                    {{$t('orderQuery.againLoan')}}
                </button>
                <!-- 订单作废 -->
                <button type='button' @click='deleteOrder' :disabled="deleteDis" v-if="orderQuery_btn_toviod">
                    {{$t('orderQuery.orderToviod')}}
                </button>
                <!-- 修改订单信息 -->
                <button type='button' @click='editInfoFn' :disabled="editInfoDis" v-if="orderQuery_edit_info">
                    {{$t('orderQuery.editOrderInfo')}}
                </button>
                <!-- 还款查询 -->
                <button type='button' @click='repayQueryFn' :disabled="repayQueryDis" v-if="orderQuery_repay_query
">
                    {{$t('orderQuery.repayQuery')}}
                </button>
            </div>
        </div>
      </el-card>
      <el-card class='box-card' style="margin-top: 10px;margin-bottom: 20px;">
        <div class='title'>
            {{$t('achievements.title2')}}
        </div>
        <el-table
            v-loading="listLoading"
            ref='multipleTable'
            :data='tableData'
            tooltip-effect='dark'
            style='width: 100%'
            @selection-change='handleSelectionChange'
            border
            stripe
            size='mini'>
            <el-table-column
            header-align='center'
            align='center'
            type='selection'
            width='55'>
            </el-table-column>
            <!-- 业务ID -->
            <el-table-column
            :label="$t('achievements.orderId')"
            width='140' align="center" header-align="center" 
          
            >
            <template slot-scope="scope">
                <span class="href" @click="hrefFn(scope.row)">{{scope.row.orderId}}</span>
                <!-- <span>{{scope.row.orderId}}</span> -->
            </template>
            </el-table-column>
            <!-- 客户姓名 -->
            <el-table-column
            prop='realName' align="center" header-align="center" 
            :label="$t('achievements.realName')"
            width='180'>
            </el-table-column>
            <!-- 手机号 -->
            <el-table-column 
            prop='appUserName' align="center" header-align="center" 
            :label="$t('achievements.phoneNo')"
            width='140'>
            </el-table-column>
            <!-- 是否续贷 -->
            <el-table-column
            prop='attr5' align="center" header-align="center" 
            :label="$t('orderQuery.ctnLoan')"
            width='120'>
            <template slot-scope="scope">
              <span v-show="scope.row.attr5=== null || scope.row.attr5=== ''">{{$t('approvalDetail.no')}}</span>
              <span v-show="scope.row.attr5=== '1' || scope.row.attr5=== '2'">{{$t('approvalDetail.yes')}}</span>
            </template>
            </el-table-column>
            <!-- 审批额度 -->
            <el-table-column 
            prop='approvedAmt' align="center" header-align="center" 
            :label="$t('orderQuery.approvalAmt')"
            width='120'>
            </el-table-column>
            <!-- 审批人 -->
            <el-table-column
            prop='businessUserName' align="center" header-align="center" 
            :label="$t('achievements.loanUser')"
            width='120'>
            </el-table-column>
            <!-- 产品名称 -->
            <el-table-column
            prop='proName' align="center" header-align="center" 
            :label="$t('achievements.proName')"
            width='120'>
            </el-table-column>
            <!-- 结清还款时间 -->
            <el-table-column
            prop='settleTime' align="center" header-align="center" 
            :label="$t('dispatch.settleTime')"
            width='180'>
            </el-table-column>
            <!-- 申请时间 -->
            <el-table-column
            prop="crtTime" align="center" header-align="center" 
            :label="$t('achievements.crtTime')"
            width='180'>
            </el-table-column>
            <!-- 放款时间 -->
            <el-table-column
            prop="lendDate" align="center" header-align="center" 
            :label="$t('orderQuery.loanTime')"
            width='180'>
            </el-table-column>
            <!-- 申请金额 -->
            <el-table-column
            prop='applyAmt' align="center" header-align="center" 
            :label="$t('orderQuery.apprAmt')"
            width='140'>
            </el-table-column>
            <!-- 放款金额 -->
            <el-table-column
            prop='neteceipts' align="center" header-align="center" 
            :label="$t('orderQuery.neteceipts')"
            width='140'>
            </el-table-column>
            <!-- 订单状态 -->
            <el-table-column
            prop='status' align="center" header-align="center" 
            :label="$t('orderQuery.orderStatus')"
            width='100'>
            <template slot-scope="scope">
              <span v-if="scope.row.status=== 1">{{$t('orderQuery.status1')}}</span>
              <span v-if="scope.row.status=== 2 && scope.row.checkStatus === 60">{{$t('orderQuery.status2')}}</span>
              <span v-if="scope.row.status=== 2 && scope.row.checkStatus === 65">{{$t('orderQuery.status11')}}</span>
              <span v-if="scope.row.status=== 3">{{$t('orderQuery.status3')}}</span>
              <span v-if="scope.row.status=== 4">{{$t('orderQuery.status4')}}</span>
              <span v-if="scope.row.status=== 5">{{$t('orderQuery.status5')}}</span>
              <span v-if="scope.row.status=== 6">{{$t('orderQuery.status6')}}</span>
              <span v-if="scope.row.status=== 7">{{$t('orderQuery.status7')}}</span>
              <span v-if="scope.row.status=== 8">{{$t('orderQuery.status8')}}</span>
              <span v-if="scope.row.status=== 9">{{$t('orderQuery.status9')}}</span>
              <span v-if="scope.row.status=== 10">{{$t('orderQuery.status10')}}</span>
            </template>
            </el-table-column>
            <!-- 到期时间 -->
            <el-table-column
            prop='lastPayDate' align="center" header-align="center" 
            :label="$t('orderQuery.lastPayDate')"
            width='200'>
            </el-table-column>
            <!-- 机构名称 -->
            <el-table-column
            prop="orgName" align="center" header-align="center" 
            :label="$t('achievements.orgName')"
            width='160'>
            </el-table-column>
            <!-- 业务渠道 -->
            <el-table-column
            prop='appShortName' align="center" header-align="center" 
            :label="$t('achievements.appShortName')"
            width='110'>
            </el-table-column>
            <!-- 借款App -->
            <el-table-column
            prop='appAllName' align="center" header-align="center" 
            :label="$t('approvalDetail.loanApp')"
            width='180'>
            </el-table-column>
            <!-- 审批结果 -->
            <el-table-column
            prop='checkUserStatus' align="center" header-align="center" 
            :label="$t('achievements.apprResult')"
            width='110'>
            <template slot-scope="scope">
              <span v-if="scope.row.checkUserStatus=== 0">{{$t('orderQuery.status1')}}</span>
              <span v-if="scope.row.checkUserStatus=== 1">{{$t('orderQuery.adopt')}}</span>
              <span v-if="scope.row.checkUserStatus=== 2">{{$t('orderQuery.refuse')}}</span>
              <span v-if="scope.row.checkUserStatus=== 3">{{$t('orderQuery.derate')}}</span>
            </template>
            </el-table-column>
            <!-- 审批意见 -->
            <el-table-column
            prop='checkOpinion' align="center" header-align="center" 
            :label="$t('achievements.checkOpinion')"
            width='300'
            show-overflow-tooltip>
            </el-table-column>
            <!-- 放宽失败原因 -->
            <el-table-column
            :label="$t('orderQuery.loanErrorReason')"
            width='120' 
            header-align="center"
            align="center">
            <template slot-scope="scope">
              <span v-show="scope.row.status=== 8">
                <a class="href" href="javascript:void(0)" @click="lookUp(scope.row)">{{$t('approvalDetail.hitsee')}}</a>
              </span>
            </template> 
            </el-table-column>
        </el-table>
        <div class="pagination-container">
          <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="listQuery.page"
          :page-sizes="[10, 30, 50, 100]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
          </el-pagination>
        </div>
      </el-card>
      <!-- 放款失败原因 -->
      <el-dialog
        :title="$t('orderQuery.loanErrorReason')"
        :visible.sync="centerDialogVisible"
        width="30%"
        style="text-align: center;"
        center>
        <span>
          <el-input
            type="textarea"
            :autosize="{ minRows: 4}"
            disabled
            v-model="textarea"
            :placeholder="$t('rule.toLength')" 
            :maxlength="500">
          </el-input>
        </span>
        <div class="dialog-footer" style="text-align: center;padding-top: 20px;">
          <el-button type="primary" @click="centerDialogVisible = false">{{$t('btn.confirm')}}</el-button>
        </div>
      </el-dialog>
      <!-- 重新放款原因 -->
      <el-dialog
        :title="$t('orderQuery.reLendingReason')"
        :visible.sync="reLendingDialogVisible"
        style="text-align: center;"
        center
        :before-close = "closeDialog">
        <el-form :model="form" :rules="rules" ref="form" label-width="110px">
          <el-form-item :label="$t('orderQuery.reLendingReason')" prop="reLendReason">
              <el-input size='small' :placeholder="$t('orderQuery.failureReasonInp')" v-model="form.reLendReason"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="cancel('form')">{{$t('btn.cancel')}}</el-button>
          <el-button type="primary" @click="againDialog('form')" :disabled="againDis">{{$t('orderQuery.againLoan')}}</el-button>
        </div>
      </el-dialog>
      <!-- 修改订单信息 -->
      <el-dialog :title="$t('orderQuery.editOrderInfo')" :visible.sync="dialogEditInfoVisible" width="30%">
          <el-form :model="infoForm" :rules="infoRules" ref="infoForm" label-width="100px">
            <el-form-item :label="$t('orderQuery.userName')" prop="realName">
              <el-input size="small" v-model="infoForm.realName" style="width: 200px;"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="saveEditInfoFn('infoForm')">{{$t('btn.confirm')}}</el-button>
            <el-button @click="editInfocancel('infoForm')">{{$t('btn.cancel')}}</el-button>
          </div>
      </el-dialog>
      <!-- 还款查询 -->
      <el-dialog :title="$t('orderQuery.repayQuery')" :visible.sync="dialogRepayQueryVisible" width="30%">
        <el-form :model="repayQueryForm" :rules="repayQueryRules" ref="repayQueryForm" label-width="120px">
          <el-form-item :label="$t('orderQuery.repayVA')" prop="paymentCode">
            <el-input size="small" v-model="repayQueryForm.paymentCode" style="width: 200px;"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="saveRepayQueryFn('repayQueryForm')">{{$t('btn.confirm')}}</el-button>
          <el-button @click="editRepayQuerycancel('repayQueryForm')">{{$t('btn.cancel')}}</el-button>
        </div>
      </el-dialog>
      <!-- 还款查询结果 -->
      <el-dialog
        :title="$t('orderQuery.repayResult')"
        :visible.sync="dialogRepayResultVisible"
        width="30%"
        center>
        <div style="text-align: center;">
          {{resultMsg}}
        </div>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dialogRepayResultVisible = false">{{$t('btn.complete')}}</el-button>
          </div>
      </el-dialog>
    </div>
</template>

<script>
import { mapGetters } from "vuex";
import { dataMasking } from 'utils/index';
import { page, loanError, bankUntied, againColl, updateOrderStatus, pageExport, yearUpUserName, repaymentQuery } from 'api/trust/orderQuery/index'
import { getListOrg } from 'api/trust/achievements/index'
export default {
  name: "orderQuery",
  data() {
    return {
      resultMsg: '',
      dialogRepayResultVisible: false,
      dialogRepayQueryVisible: false,
      repayQueryForm: {
        paymentCode: ''
      },
      repayQueryRules: {
        paymentCode: [
          { required: true, message: this.$t('orderQuery.repayVAInp'), trigger: 'blur' }
        ],
      },
      dialogEditInfoVisible: false,
      infoForm: {
        realName: ''
      },
      infoRules: {
        realName: [
          { required: true, message: this.$t('userManagement.ruleUser'), trigger: 'blur' }
        ],
      },
      form: {
        reLendReason: '',
      },
      rules: {
        reLendReason: [
          { required: true, message: this.$t('orderQuery.failureReasonInp'), trigger: 'blur' }
        ]
      },
      reLendingDialogVisible: false,
      orderQuery_btn_export: false,
      deleteDis: true,
      editInfoDis: true,
      repayQueryDis: true,
      againDis: true,
      orderQuery_btn_untie: false,
      orderQuery_btn_again: false,
      orderQuery_btn_toviod: false,
      orderQuery_edit_info: false,
      orderQuery_repay_query: false,
      textarea: '',
      centerDialogVisible: false,
      untieDis: true,
      expDis: true,
      listLoading: false,
      total: null,
      listQuery: {
        limit: 10,
        page: 1,
        orgId: '', // 机构ID
        orderId: '', // 业务ID
        realName: '',
        phoneNo: '',
        approvalResult: 0, // 全部0 通过1拒绝2降额3
        checkStatus: '', // 订单状态
        beginDate: '', // 申请时间
        endDate: '',
        loanUser: '',
        lendBeginDate: '', // 放款时间
        lendEndDate: '',
        repaymengtBeginDate: '', // 到期时间
        repaymengtEndDate: '',
        continuedLoanStatus: "",
        beginSettleTime: "", //结清还款时间
        endSettleTime: ""
      },
      tableData: [],
      multipleSelection: [],
      mechanism: [
        {
          id: 0,
          orgName: this.$t('rule.choose')
      }],
      result: [
        {
          value: 0,
          label: this.$t('rule.all')
        },
        {
          value: 2,
          label: this.$t('approval.adopt')
        },
        {
          value: 3,
          label: this.$t('approval.refuse')
        },
        // {
        //   value: 4,
        //   label: this.$t('approval.derate')
        // },
        {
          value: 1,
          label: this.$t('approval.audit')
        }
      ],
      orderStatus: [
        {
          value: 0,
          label: this.$t('rule.choose')
        },
        {
          value: 1,
          label: this.$t('orderQuery.status1')
        },
        {
          value: 2,
          label: this.$t('orderQuery.adopt')
        },
        {
          value: 3,
          label: this.$t('orderQuery.refuse')
        },
        {
          value: 4,
          label: this.$t('orderQuery.status3')
        },
        {
          value: 5,
          label: this.$t('orderQuery.status5')
        },
        {
          value: 6,
          label: this.$t('orderQuery.status6')
        },
        {
          value: 7,
          label: this.$t('orderQuery.status7')
        },
        {
          value: 8,
          label: this.$t('orderQuery.status8')
        },
        {
          value: 9,
          label: this.$t('orderQuery.status9')
        },
        {
          value: 10,
          label: this.$t('orderQuery.status10')
        }
      ],
      conLoan: [
        {
          value: '',
          label: this.$t('rule.all')
        },
        {
          value: 1,
          label: this.$t('approvalDetail.yes')
        },
        {
          value: 2,
          label: this.$t('approvalDetail.no')
        }
      ]
    };
  },
  created() {
    let obj = {};
    getListOrg(obj) 
    .then(response => {
      this.mechanism = this.mechanism.concat(response.data.orgList);
    })
    if (this.orderPage.has(this.$route.path)) {
      this.listQuery = this.orderPage.get(this.$route.path)
    }
    this.getTime();
    this.getList();
    this.orderQuery_btn_untie = this.elements['orderQuery:btn_untie'];
    this.orderQuery_btn_again = this.elements['orderQuery:btn_again'];
    this.orderQuery_btn_toviod = this.elements['orderQuery:btn_toviod'];
    this.orderQuery_btn_export = this.elements['orderQuery:btn_export'];
    this.orderQuery_edit_info = this.elements['orderQuery:edit_info'];
    this.orderQuery_repay_query = this.elements['orderQuery:repay_query'];
  },
  computed: {
    ...mapGetters(["elements", "orderPage", "device"])
  },
  methods: {
    hrefFn(row) {
      this.$store.dispatch("setApprAchiCountDetails", row);
      this.$router.push({
        path: "/AuditReport/apprAchiCountDetails",
        name: "订单详情"
      });
    },
    getTime() {
      this.listQuery.beginDate = this.GetDateStr(-2);
      this.listQuery.endDate = this.GetDateStr(0);
    },
    GetDateStr(AddDayCount) {
      let dd = new Date();
      dd.setDate(dd.getDate() + AddDayCount);// 获取AddDayCount天后的日期
      let y = dd.getFullYear();
      let m = (dd.getMonth() + 1) < 10 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1); // 获取当前月份的日期，不足10补0
      let d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate(); // 获取当前几号，不足10补0
      return y + '-' + m + '-' + d;
    },
    closeDialog(done) {
      done();
      this.$refs["form"].resetFields();
      this.getList()
    },
    // 还款查询
    repayQueryFn() {
      if (this.multipleSelection.length <= 0){
        this.$message({
          showClose: true,
          message: this.$t('approval.msg1'),
          type: 'warning'
        });
      } else if (this.multipleSelection.length > 1){
        this.$message({
          showClose: true,
          message: this.$t('approval.msg2'),
          type: 'warning'
        });
      } else {
        this.repayQueryForm.paymentCode = '';
        this.dialogRepayQueryVisible = true;
      }
    },
    // 还款查询确认
    saveRepayQueryFn(formName) {
      const set = this.$refs;
      set[formName].validate(valid => {
        if (valid) {
          this.$confirm(this.$t("approvalDetail.cue1"), {
            confirmButtonText: this.$t("btn.confirm"),
            cancelButtonText: this.$t("btn.cancel"),
            type: "warning",
            center: true
          })
            .then(() => {
              let obj = {};
              obj.orderId = this.multipleSelection[0].orderId;
              obj.paymentCode = this.repayQueryForm.paymentCode;
              repaymentQuery(obj)
              .then(res => {
                if (res.status === 200) {
                  this.dialogRepayQueryVisible = false;
                  this.resultMsg = res.data.message;
                  this.dialogRepayResultVisible = true;
                } else {
                  this.$message({
                    showClose: true,
                    type: "warning",
                    message: res.message
                  });
                }
              })
            })
            .catch(() => {
              this.$message({
                showClose: true,
                type: "info",
                message: this.$t("loanDetail.cue3")
              });
            });
        } else {
          return false;
        }
      });
    },
    editRepayQuerycancel(formName) {
      this.dialogRepayQueryVisible = false;
      this.$refs[formName].resetFields();
    },
    // 修改订单信息
    editInfoFn() {
      if (this.multipleSelection.length <= 0){
        this.$message({
          showClose: true,
          message: this.$t('approval.msg1'),
          type: 'warning'
        });
      } else if (this.multipleSelection.length > 1){
        this.$message({
          showClose: true,
          message: this.$t('approval.msg2'),
          type: 'warning'
        });
      } else {
        this.infoForm.realName = '';
        this.dialogEditInfoVisible = true;
      }
    },
    // 修改订单信息确认
    saveEditInfoFn(formName) {
      const set = this.$refs;
      set[formName].validate(valid => {
        if (valid) {
          this.$confirm(this.$t("approvalDetail.cue1"), {
            confirmButtonText: this.$t("btn.confirm"),
            cancelButtonText: this.$t("btn.cancel"),
            type: "warning",
            center: true
          })
            .then(() => {
              let obj = {};
              obj.orderId = this.multipleSelection[0].orderId;
              obj.realName = this.infoForm.realName;
              yearUpUserName(obj)
              .then(res => {
                this.$message({
                  showClose: true,
                  type: "success",
                  message: this.$t("approvalDispatch.opersuccess")
                });
                this.dialogEditInfoVisible = false;
                this.getList();
              })
            })
            .catch(() => {
              this.$message({
                showClose: true,
                type: "info",
                message: this.$t("loanDetail.cue3")
              });
            });
        } else {
          return false;
        }
      });
    },
    editInfocancel(formName) {
      this.dialogEditInfoVisible = false;
      this.$refs[formName].resetFields();
    },
    // 订单作废
    deleteOrder() {
      if (this.multipleSelection.length === 1){   
        this.$confirm(this.$t('orderQuery.cue4'), {
          confirmButtonText: this.$t('btn.confirm'),
          cancelButtonText: this.$t('btn.cancel'),
          type: "warning",
          center: true
        })
        .then(() => {
          this.deleteDis = true;
          let obj = {};
          obj.orderId = this.multipleSelection[0].orderId;
          obj.status = 9;
          updateOrderStatus(obj)
          .then(res => {
            if (res.status === 200) {
              this.getList();
              this.deleteDis = false;
              this.$message({
                showClose: true,
                message: this.$t('approvalDispatch.opersuccess'),
                type: 'success'
              });
            }
          })
        })
        .catch(() => {
          this.$message({
            showClose: true,
            type: "info",
            message: this.$t('orderQuery.cue2')
          });
        });
      } else if (this.multipleSelection.length <= 0){
        this.$message({
          showClose: true,
          message: this.$t('approval.msg1'),
          type: 'warning'
        });
      } else if (this.multipleSelection.length > 1) {
        this.$message({
          showClose: true,
          message: this.$t('approval.msg2'),
          type: 'warning'
        });
      }
    },
    // 查看失败原因 
    lookUp(row) {
      this.centerDialogVisible = true;
      loanError(row.orderId) 
      .then(res => {
        this.textarea = res.data.msg;
      }) 
    },
    // 解绑银行卡
    untie() {
      if (this.multipleSelection.length <= 0){
        this.$message({
          showClose: true,
          message: this.$t('approval.msg1'),
          type: 'warning'
        });
      } else {
        this.$confirm(this.$t('orderQuery.cue3'), {
          confirmButtonText: this.$t('btn.confirm'),
          cancelButtonText: this.$t('btn.cancel'),
          type: "warning",
          center: true
        })
        .then(() => {
          this.untieDis = true;
          let arr = [];
          this.multipleSelection.forEach(item => {
            arr.push(item.orderId)
          })
          let obj = {};
          obj.orderIds = arr;
          bankUntied(obj)
          .then(res => {
            if (res.status === 200) {
              this.getList();
              this.untieDis = false;
              this.$message({
                showClose: true,
                message: this.$t('orderQuery.sus2'),
                type: 'success'
              });
            }
          })
        })
        .catch(() => {
          this.$message({
            showClose: true,
            type: "info",
            message: this.$t('orderQuery.cue2')
          });
        });
      }
    },
    // 重新放款
    again() {
      if (this.multipleSelection.length === 1 && this.multipleSelection[0].status === 8){
        this.form = {
          reLendReason: ''
        }
        this.reLendingDialogVisible = true;
      } else if (this.multipleSelection.length <= 0){
        this.$message({
          showClose: true,
          message: this.$t('approval.msg1'),
          type: 'warning'
        });
      } else if (this.multipleSelection.length > 1) {
        this.$message({
          showClose: true,
          message: this.$t('approval.msg2'),
          type: 'warning'
        });
      }
    },
    // 重新放款确认
    againDialog(formName) {
      const set = this.$refs;
      set[formName].validate(valid => {
        if (valid) {
          this.$confirm(this.$t('orderQuery.cue1'), {
            confirmButtonText: this.$t('btn.confirm'),
            cancelButtonText: this.$t('btn.cancel'),
            type: "warning",
            center: true
          })
          .then(() => {
            this.againDis = true;
            againColl(this.multipleSelection[0].orderId, this.form)
            .then(res => {
              if (res.status === 200) {
                this.reLendingDialogVisible = false;
                this.getList();
                this.againDis = false;
                this.$message({
                  showClose: true,
                  message: this.$t('orderQuery.sus1'),
                  type: 'success'
                });
              }
            })
          })
          .catch(() => {
            this.$message({
              showClose: true,
              type: "info",
              message: this.$t('orderQuery.cue2')
            });
          });
        } else {
          return false;
        }
      });
    },
    // 点击导出
    handleDownload() {
      this.listLoading = true;
      pageExport(this.listQuery)
      .then(response => {
        response.data.forEach(item => {
          if (item.realName || item.appUserName) {
            item.realName = dataMasking(item.realName)
            item.appUserName = dataMasking(item.appUserName)
          }
          // 是否续贷
          if (item.attr5 === null || item.attr5 === '') {
            item.attr5 = this.$t('approvalDetail.no')
          } else if (item.attr5 === '1' || item.attr5 === '2') {
            item.attr5 = this.$t('approvalDetail.yes')
          }
          // 审批结果
          switch (item.checkUserStatus) {
            case 0:
              item.checkUserStatus = this.$t('orderQuery.status1')
              break;
            case 1:
              item.checkUserStatus = this.$t('orderQuery.adopt')
              break;
            case 2:
              item.checkUserStatus = this.$t('orderQuery.refuse')
              break;
            case 3:
              item.checkUserStatus = this.$t('orderQuery.derate')
              break;
          }
          // 订单状态
          if (item.status === 1) {
            item.status = this.$t('orderQuery.status1')
          } else if(item.status === 2 && item.checkStatus === 60) {
            item.status = item.status = this.$t('orderQuery.status2')
          } else if(item.status === 2 && item.checkStatus === 65) {
            item.status = item.status = this.$t('orderQuery.status11')
          } else if(item.status === 3) {
            item.status = item.status = this.$t('orderQuery.status3')
          } else if(item.status === 4) {
            item.status = item.status = this.$t('orderQuery.status4')
          } else if(item.status === 5) {
            item.status = item.status = this.$t('orderQuery.status5')
          } else if(item.status === 6) {
            item.status = item.status = this.$t('orderQuery.status6')
          } else if(item.status === 7) {
            item.status = item.status = this.$t('orderQuery.status7')
          } else if(item.status === 8) {
            item.status = item.status = this.$t('orderQuery.status8')
          } else if(item.status === 9) {
            item.status = item.status = this.$t('orderQuery.status9')
          } else if(item.status === 10) {
            item.status = item.status = this.$t('orderQuery.status10')
          }
        })
        require.ensure([], () => {
          const { export_json_to_excel } = require('@/vendor/Export2Excel')
          const tHeader = [ this.$t('achievements.orderId'), this.$t('achievements.realName'), this.$t('achievements.phoneNo'), this.$t('orderQuery.ctnLoan'), this.$t('orderQuery.approvalAmt'), this.$t('achievements.loanUser'), this.$t('achievements.proName'), this.$t('dispatch.settleTime'), this.$t('achievements.crtTime'), this.$t('orderQuery.loanTime'), this.$t('orderQuery.apprAmt'), this.$t('orderQuery.neteceipts'), this.$t('orderQuery.orderStatus'), this.$t('orderQuery.lastPayDate'), this.$t('achievements.orgName'), this.$t('achievements.appShortName'), this.$t('approvalDetail.loanApp'), this.$t('achievements.apprResult'), this.$t('achievements.checkOpinion') ];
          const filterVal = [ 'orderId', 'realName', 'appUserName', 'attr5', 'approvedAmt', 'businessUserName', 'proName', 'settleTime', 'crtTime', 'lendDate', 'applyAmt', 'neteceipts', 'status', 'lastPayDate', 'orgName', 'appShortName', 'appAllName', 'checkUserStatus', 'checkOpinion' ];
          const list = response.data;
          const data = this.formatJson(filterVal, list)
          export_json_to_excel(tHeader, data, this.$t('route.orderQuery'))
          this.listLoading = false;
        })
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        // if (j === 'realName' || j === 'appUserName') {
        //   return dataMasking(v[j])
        // }
        return v[j]
      }))
    },
    getList() {
      this.listLoading = true;
      this.$store.dispatch('saveOrderPage', { path: this.$route.path, listQuery: this.listQuery });
      if (this.multipleSelection.length === 1) {
        this.editInfoDis = false;
        this.repayQueryDis = false;
        if (this.listQuery.status === 8) {
          this.againDis = false;
        } else {
          this.againDis = true;
        }
        if (this.listQuery.status === 8 || this.listQuery.checkStatus === 40 || this.listQuery.checkStatus === 45) {
          this.untieDis = false;
        } else {
          this.untieDis = true;
        }
        if ((this.listQuery.status === 3 
        || this.listQuery.status === 5 
        || this.listQuery.status === 6 
        || this.listQuery.status === 7)) {
          this.deleteDis = true;
        } else {
          this.deleteDis = false;
        }
      } else {
        this.deleteDis = true;
        this.editInfoDis = true;
        this.repayQueryDis = true;
        this.untieDis = true;
        this.againDis = true;
      }
      page(this.listQuery)
        .then(response => {
          response.data.rows.forEach(item => {
            let re = /(?=(?!\b)(\d{3})+$)/g;
            let str = String(item.applyAmt)
            item.applyAmt =  str.replace(re, ',');
            let str2 = String(item.neteceipts)
            item.neteceipts = str2.replace(re, ',');
            let str3 = String(item.approvedAmt)
            item.approvedAmt = str3.replace(re, ',');
          })
          if (response.status === 200) {
            this.expDis = false;
            this.listLoading = false;
            this.tableData = response.data.rows;
            this.total = Number(response.data.total);
          }
        })
    },
    // 查询
    search() {
      this.listQuery.page = 1;
      this.getList();
    },
    // 重置
    reset() {
      this.listQuery.limit = 10;
      this.listQuery.page = 1;
      this.listQuery.orgId = "";
      this.listQuery.orderId = "";
      this.listQuery.realName = "";
      this.listQuery.phoneNo = "";
      this.listQuery.approvalResult = 0;
      this.listQuery.checkStatus = "";
      this.listQuery.beginDate = this.GetDateStr(-2);
      this.listQuery.endDate = this.GetDateStr(0);
      this.listQuery.lendBeginDate = '';
      this.listQuery.lendEndDate = '';
      this.listQuery.repaymengtBeginDate = '';
      this.listQuery.repaymengtEndDate = '';
      this.listQuery.beginSettleTime = '';
      this.listQuery.endSettleTime = '';
      this.listQuery.loanUser = "";
      this.listQuery.continuedLoanStatus = "";
    },
    // 选中的数据
    handleSelectionChange(val) {
      this.multipleSelection = val;
      if(this.multipleSelection.length === 1) {
        this.editInfoDis = false;
        this.repayQueryDis = false;
        this.multipleSelection.forEach(item => {
          if (item.status === 8) {
            this.againDis = false;
          } else {
            this.againDis = true;
          }
          if (item.status === 8 || item.checkStatus === 40 || item.checkStatus === 45) {
            this.untieDis = false;
          } else {
            this.untieDis = true;
          }
          if ((item.status === 3 
          || item.status === 5 
          || item.status === 6 
          || item.status === 7)) {
            this.deleteDis = true;
          } else {
            this.deleteDis = false;
          }
        })
      } else {
        this.deleteDis = true;
        this.editInfoDis = true;
        this.repayQueryDis = true;
        this.untieDis = true;
        this.againDis = true;
      }
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList()
    },
    cancel(formName) {
      this.reLendingDialogVisible = false;
      this.$refs[formName].resetFields();
    },
  }
};
</script>

<style scoped lang='scss'>
.box-card {
  width: 95%;
  margin-left: 2.5%;
  margin-right: 2.5%;
}
.title {
  line-height: 30px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before{
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-title {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .searchItem {
    display: flex;
    align-items: center;
    padding: 10px  0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div:nth-child(2) {
      width: 150px;
    }
  }
  .searchItem-date {
    display: flex;
    align-items: center;
    padding: 10px  0;
    b {
      margin: 0 10px;
      font-weight: normal;
      font-size: 12px;
      color: #5f5f61;
    }
    div {
       width: 150px;
    }
  }
}
.menu-title-btn {
  padding: 10px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    margin-top: 10px;
    // &:nth-child(1) {
    //   margin-left: 0;
    // }
    &:nth-child(2) {
      background: #ebf5ff;
      color: #20a0ff;
      border: 1px solid #abd5ff;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.menu-list {
  padding: 20px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.href {
  border-bottom: 1px solid #000;
  cursor: pointer;
  &:hover {
    color: #20a0ff;
    border-bottom: 1px solid #20a0ff;
  }
}
.clear-redis /deep/.el-dialog {
  width: 400px;
}
</style>